import axios from 'axios'
import Cookies from "js-cookie";
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
const service = axios.create({
    // axios中请求配置有baseURL选项，表示请求URL公共部分
    baseURL: process.env.VUE_APP_BASE_API,
    // 超时
    timeout: 10000
})
service.interceptors.response.use(res => {
    return res.data
})
service.interceptors.request.use(config => {
    if (Cookies.get("Admin-Token")) {
        config.headers['Authorization'] = 'Bearer ' + Cookies.get("Admin-Token") // 让每个请求携带自定义token 请根据实际情况自行修改
    }
    return config
}, error => {
    console.log(error)
    Promise.reject(error)
})

export default service